
package com.csz.actions;

import com.csz.model.Imagem;
import java.io.ByteArrayInputStream;
import java.io.OutputStream;

/* @author Arthur F. Zanona */

public class ActionImagem extends Action {

    @Override
    public void execute() {
        try {
            response.setContentType("image/jpeg");
            Imagem i = (Imagem) Imagem.consultar( Integer.parseInt(request.getParameter("img_id")) );
            ByteArrayInputStream in = new ByteArrayInputStream( i.getImagem() );
            OutputStream out = response.getOutputStream();
            int b;
            while ((b = in.read()) != -1) {
                out.write(b);
            }
            in.close();
            out.flush();
            out.close();

        }
        catch (Exception exception ) {

        }
    }

}
